package com.googlecode.ivybeans.module.classpath;

import com.googlecode.ivybeans.facade.ResolvedIvyLibrary;
import java.util.HashMap;
import java.util.Map;

public class ScopeConfigurationMapping {

    public enum DefaultConfEnum {

        COMPILE("compile"), RUNTIME("runtime"), COMPILE_TEST("compile-test"), RUNTIME_TEST("runtime-test");
        private String name;

        private DefaultConfEnum(String name) {
            this.name = name;
        }

        public String getName() {
            return name;
        }
    }
    private final Map<ClassPathScope, String[]> configurationMap = new HashMap<ClassPathScope, String[]>();
    private Map<ClassPathScope, ResolvedIvyLibrary> resolvedIvyLibraryMap = new HashMap<ClassPathScope, ResolvedIvyLibrary>();

    public ScopeConfigurationMapping() {
        super();
    }

    public void put(ClassPathScope scope, String[] confs, ResolvedIvyLibrary resolvedIvyLibrary) {
        synchronized (configurationMap) {
            resolvedIvyLibraryMap.put(scope, resolvedIvyLibrary);
            configurationMap.put(scope, confs);
        }
    }

    public String[] getConfiguration(ClassPathScope scope) {
        return configurationMap.get(scope);
    }

    public ResolvedIvyLibrary getResolvedIvyLibrary(ClassPathScope scope) {
        return resolvedIvyLibraryMap.get(scope);
    }

    public static ScopeConfigurationMapping createDefault() {
        ScopeConfigurationMapping confMapping = new ScopeConfigurationMapping();
        confMapping.put(ClassPathScope.COMPILE, new String[]{DefaultConfEnum.COMPILE.getName()}, ResolvedIvyLibrary.EMPTY_RESOLVED);
        confMapping.put(ClassPathScope.PROCESSOR, new String[]{DefaultConfEnum.COMPILE.getName()}, ResolvedIvyLibrary.EMPTY_RESOLVED);
        confMapping.put(ClassPathScope.COMPILE_TEST,
                new String[]{DefaultConfEnum.COMPILE.getName(), DefaultConfEnum.COMPILE_TEST.getName()},
                ResolvedIvyLibrary.EMPTY_RESOLVED);
        confMapping.put(ClassPathScope.RUNTIME,
                new String[]{DefaultConfEnum.COMPILE.getName(), DefaultConfEnum.RUNTIME.getName()},
                ResolvedIvyLibrary.EMPTY_RESOLVED);
        confMapping.put(ClassPathScope.RUNTIME_TEST,
                new String[]{DefaultConfEnum.COMPILE.getName(), DefaultConfEnum.COMPILE_TEST.getName(), DefaultConfEnum.RUNTIME.getName(), DefaultConfEnum.RUNTIME_TEST.getName()},
                ResolvedIvyLibrary.EMPTY_RESOLVED);

        return confMapping;
    }
}
